let head = [1, 2, 3, 4, 5]
function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}
let list = new ListNode(head[0])
let num = list
for (let i = 1; i < head.length; i++) {
    num.next = new ListNode(head[i])
    num = num.next
};
var reverseList = function (head) {
    let pre = null
    let cur = head
    while (cur) {
        const nxt = cur.next
        cur.next = pre
        pre = cur
        cur = nxt
    }
    return pre
};
console.log(reverseList(list));
